feat(nav2): add workspace bounds and coordinate safety validation - #871
Merged
Merged
Conversation
Introduce workspace boundary bounding and coordinate safety validation for Nav2 navigation tools (NavigateToPoseTool, NavigateToPoseBlockingTool, and Nav2Toolkit). When autonomous agents or LLMs propose target poses, unconstrained or out-of-bounds coordinates risk sending physical robots and simulation models into dangerous or unmapped areas. This change provides deterministic spatial bounding and numeric validation: - Adds validate_finite_coordinate, validate_workspace_bounds, and validate_pose_within_bounds in rai.tools.coordinates. - Re-exports bounds validation helpers in rai.tools.ros2.navigation.bounds. - Adds optional workspace_bounds_min and workspace_bounds_max parameters to NavigateToPoseTool, NavigateToPoseBlockingTool, and Nav2Toolkit. - Validates that target coordinates are finite numbers and within configured workspace bounds before dispatching ROS 2 action goals. - Provides comprehensive offline unit test suite with 37 test cases covering valid coordinates, bounds boundary conditions, dimension violations, and non-finite number rejection.
ved197338
marked this pull request as ready for review
September 4, 2026 09:19
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #871 +/- ##
==========================================
+ Coverage 74.49% 74.69% +0.20%
==========================================
Files 82 83 +1
Lines 3627 3652 +25
==========================================
+ Hits 2702 2728 +26
+ Misses 925 924 -1 ☔ View full report in Codecov by Harness. |
Keeps the feature and folds the validation into the tool models. The bounds live on a WorkspaceBounds mixin shared by NavigateToPoseTool, NavigateToPoseBlockingTool and Nav2Toolkit, which propagates them. Their ordering is checked once when the tool is built rather than on every goal, and Tuple[Coordinate, ...] with allow_inf_nan=False covers the shape and finiteness that coordinates.py checked by hand, so that module and its re-exports are gone. Also adds allow_inf_nan=False to NavigateToPoseBlockingToolInput, which was missed in RobotecAI#872, and constrains the bounds themselves: a plain float tuple accepts NaN, and NaN bounds silently disable every comparison. Tests now exercise the tools rather than the helpers: an out-of-bounds goal is refused before the connector is touched, one-sided bounds only constrain their side, and inverted or malformed bounds fail at construction.
Member
|
Thanks for this, genuinely nice feature. I pushed a refactor commit on top to make it fit the way the rest of rai does validation, same behaviour with less code. Otherwise it stays as you wrote it. |
maciejmajek
self-requested a review
September 8, 2026 11:27
maciejmajek
approved these changes
Sep 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
This PR adds spatial workspace bounding and coordinate safety validation to RAI's Nav2 navigation tools (
NavigateToPoseTool,NavigateToPoseBlockingTool, andNav2Toolkit).Problem & Motivation
When LLM agents or autonomous planners generate navigation goals, unconstrained or hallucinated coordinates risk directing physical robots into unmapped areas, restricted zones, obstacles, or invalid elevations. Currently, coordinates (
x,y,z,yaw) are passed directly to Nav2 action goals without workspace envelope checking.Introducing deterministic workspace bounding allows deployment engineers to configure spatial envelopes (
workspace_bounds_minandworkspace_bounds_max). Target coordinates outside configured bounds or containing non-finite numbers (NaN, Inf, booleans) are rejected deterministically before any ROS 2 action is dispatched, protecting physical hardware and simulation environments.Proposed Changes
New validation module (
rai.tools.coordinates):validate_finite_coordinate: Validates that coordinates are finite numbers, rejecting NaN, Inf, booleans, and non-numeric types.validate_workspace_bounds: Verifies that(x, y, z)bounding box specifications are well-formed and minimum coordinates do not exceed maximum coordinates.validate_pose_within_bounds: Validates pose coordinates and verifies they satisfy configured workspace bounds.Navigation re-export (
rai.tools.ros2.navigation.bounds):Tool integration:
NavigateToPoseTool(nav2.py): Added optionalworkspace_bounds_minandworkspace_bounds_maxfields. Validates coordinates in_run().NavigateToPoseBlockingTool(nav2_blocking.py): Added optionalworkspace_bounds_minandworkspace_bounds_maxfields. Validates coordinates in_run().Nav2Toolkit(nav2.py): Added optionalworkspace_bounds_minandworkspace_bounds_maxfields, propagating them to child tools inget_tools().Package exports:
rai.toolsandrai.tools.ros2.navigation.Architecture & Compatibility
rai.tools(liketimeout.py).rai.tools.coordinateshas zero external dependencies and does not require ROS 2 to import or test offline.default=None). Existing deployments and code that do not configure bounds continue operating with unconstrained navigation, while gaining protection against non-finite numbers.ValueErrorexceptions, which LangChain'sToolRunnerconverts into structured error feedback for the LLM to self-correct safely.Testing
Added comprehensive unit test suite in
tests/tools/test_coordinates.py(37 test cases, 100% passing):tests/tools/test_tool_input_args_compatibility.py.Limitations & Out of Scope
/cmd_velpublishers are out of scope for this navigation action PR and can be addressed in a follow-up.